#!/usr/bin/env python3
import fileinput
import re
import sys
import os
sys.path += [os.path.join(os.path.dirname(__file__), 'deps', 'argh')]
import argh

def splitby(*by, join=b'\n'):
  pat = '(' + '|'.join([rf'(?:{x})' for x in by]) + ')'
  pat = re.compile((pat+'+').encode('utf-8'), flags=0)
  data = sys.stdin.buffer.read()
  result = re.sub(pat, join, data)
  #return result
  #print(join.join(re.split(pat, data)), end='', flush=True)
  #print(result, end='', flush=True, file=sys.stdout.buffer)
  sys.stdout.buffer.write(result)
  sys.stdout.buffer.flush()

if __name__ == '__main__':
  argh.dispatch_command(splitby)
  sys.exit(0)

#args = sys.argv[1:]
#if len(args) <= 0:
#    pass

#by = [' ']
#if len(args) > 0:
#    # by = [x.decode('unicode-escape') for x in args]
#    # by = [str.encode(x).decode('unicode-escape') for x in args]
#    by = args

#pat = '(' + '|'.join([rf'(?:{x})' for x in by]) + ')'
#pat = re.compile(pat+'+', flags=0)

#data = sys.stdin.read()
#print(re.sub(pat, '\n', data), end='', flush=True)
##print('\n'.join(by))
#import sys
#sys.exit(0)
##for i, x in enumerate(by):
#  #print(i, x, end='')

##import sys
##sys.exit(0)


#def dedup(s, x):
#    s1 = s.replace(x+x, x)
#    if len(s1) == len(s):
#        return s1
#    return dedup(s1, x)

## this is completely awful, but...  ... Well, no, it's just completely
## awful.
#MAGIC = '~~[-[~~[splitby]~~]-]~~'
#for x in by:
#    data = data.replace(x, MAGIC)
#    data = dedup(data, MAGIC)

#    # # strip newlines.
#    # data = data.replace('\n', '').replace('\r','')

#    # output = '\n'.join(data.split(MAGIC))
#    # while output.find('\n\n') >= 0:
#    #     output = output.replace('\n\n', '\n')
#    # sys.stdout.write(output.lstrip())

#    data = '\n'.join(data.split(MAGIC))
#sys.stdout.write(data)

